import {GameEngine} from "./gameEngine"
import { Bullets } from "./bullets";

const myPlane={
  el:"" as unknown as HTMLDivElement,
  num:0,
  numboom:0,
  init(num:number = 1000){
    this.num = num;

    //添加战机
    this.el = document.createElement("div");
    this.el.className = "myplane";
    GameEngine.el.appendChild(this.el);
    this.el.style.bottom = '0px';

    this.el.style.left = GameEngine.el.offsetWidth / 2 - this.el.offsetWidth / 2 + 'px';

    return this;
  },
  fire() {
    let timer = setInterval(() => {
      new Bullets().move();
    }, this.num);
  },
  boom() {
    
    // let numboom = 0;
    let timer = setTimeout(()=>{
      this.numboom=this.numboom+1;
      // console.log(this.numboom);
      this.el.style.backgroundImage = `url(./images/me_die${this.numboom}.png)`;
      if (this.numboom >= 4) {
        clearInterval(timer);
        this.el.remove();
        new Bullets().hide();
        alert("游戏结束")
      }
    },20)
  }

}


export {myPlane};
